package com.model.defaults.actionbar.entities;

import java.util.Map;

import org.hibernate.Session;

import com.core.utils.GlobalConstants;
import com.model.ActionBarItem;
import com.model.ActionScript;
import com.model.KeyValue;
import com.model.UserContextName;

public class ModelDefaultActionbarItemsTask {

	public static void createActionBarItems ( Session session,
	                                          Map <String, UserContextName> userContexts ) {

		ModelDefaultActionbarItemsTask.createActionBarItemsTaskAdd(session, userContexts);

		ModelDefaultActionbarItemsTask.createActionBarItemsTaskSubtaskAdd(session, userContexts);

		ModelDefaultActionbarItemsTask.createActionBarItemsTaskUpdate(session, userContexts);

		ModelDefaultActionbarItemsTask.createActionBarItemsTaskOpen(session, userContexts);

		ModelDefaultActionbarItemsTask.createActionBarItemsProjectSubTask(session, userContexts);
	}



	private static void createActionBarItemsProjectSubTask ( Session session,
	                                                         Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		KeyValue actionScriptParam = new KeyValue("p1", "?");
		actionScriptParam.setUserInfo(GlobalConstants.ACTIONSCRIPT_USERINFO_PARAM_KEY);
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptText("%s?{p1}", GlobalConstants.SERVLET_SUBTASKADD);
		actionScript.setActionScriptType("servlet");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_SUBTASKSLIST);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TASKADD);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.addtask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);
	}



	private static void createActionBarItemsTaskOpen ( Session session,
	                                                   Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		KeyValue actionScriptParam = new KeyValue("p1", "?");
		actionScriptParam.setUserInfo(GlobalConstants.ACTIONSCRIPT_USERINFO_PARAM_KEY);
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("servlet");
		actionScript.setActionScriptText("%s?{p1}", GlobalConstants.SERVLET_TASKUPDATE);
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TASKAINFO);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TASKAUPDATE);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.edittask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsTaskSubtaskAdd ( Session session,
	                                                         Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_SUBTASKADD);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TASKADD);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.addtask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsTaskAdd ( Session session,
	                                                  Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TASKADD);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TASKADD);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.addtask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsTaskUpdate ( Session session,
	                                                     Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TASKAUPDATE);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TASKAUPDATE);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.updatetask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}

}
